﻿<UserControl xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"  x:Class="Fdd.Aspen.Client.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:converter="clr-namespace:Fdd.Aspen.Client.ViewModels.Converters;assembly=Fdd.Aspen.Client.ViewModels"
    xmlns:edit="clr-namespace:Fdd.Aspen.Client"
    xmlns:control="clr-namespace:Fdd.Aspen.Client.Controls"
    xmlns:vm="clr-namespace:Fdd.Aspen.Client.ViewModels;assembly=Fdd.Aspen.Client.ViewModels"
    mc:Ignorable="d"
    d:DesignHeight="600" d:DesignWidth="800"
    d:DataContext="{d:DesignInstance Type=vm:ListMemberViewModel, IsDesignTimeCreatable=False}"
    DataContext="{Binding Source={StaticResource VMLocator}, Path=Find[ListMemberViewModel]}">

    <UserControl.Resources>
        <converter:EntiySateConverter x:Name="entityStateConverter"/>
        <converter:EntiyValidationConverter x:Name="entiyValidationConverter"/>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="0.10*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <my:BusyIndicator Grid.RowSpan="3" VerticalAlignment="Center" HorizontalAlignment="Center" IsBusy="{Binding IsBusy}"/>

        <control:Error Margin="5" x:Name="errorMessage" Grid.Row="0" Grid.ColumnSpan="2" ErrorMessage="{Binding Path=Exception}" ShowError="{Binding Path=ShowError}" />

        <TextBlock Grid.Row="1" Margin="10" Text="Members" FontSize="30" Foreground="Gray"/>

        <Grid Margin="10" Grid.Row="2">

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.5*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Grid>

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <StackPanel Orientation="Horizontal">
                    <TextBox x:Name="searchCustomerTextBox" Width="150"/>
                    <Button Margin="4,0,0,0" Width="50" Content="Search" x:Name="searchButton"/>
                    <Button Margin="4,0,0,0" Width="50" Content="More" x:Name="moreButton"/>
                </StackPanel>

                <ListBox Margin="0,10,0,0" BorderThickness="0,0,1,0" Grid.Row="1" x:Name="customersListBox" ItemsSource="{Binding Path=Members}" SelectedItem="{Binding Path=SelectedMember, Mode=TwoWay}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>

                                <StackPanel Margin="8,0,0,0" Orientation="Horizontal">
                                    <TextBlock Margin="4" FontSize="16" Text="{Binding FirstName}"/>
                                    <TextBlock Margin="4" FontSize="16" Text="{Binding LastName}"/>
                                </StackPanel>

                                <Border Grid.RowSpan="2" BorderBrush="{Binding EntityState, Converter={StaticResource entityStateConverter}}" BorderThickness="6,0,0,1"/>
                                <Border Grid.RowSpan="2" BorderBrush="{Binding HasValidationErrors, Converter={StaticResource entiyValidationConverter}}" BorderThickness="6,0,0,1"/>

                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

            </Grid>

            <Grid Grid.Column="1" Margin="10,0,0,0">

                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>


                <edit:EditMember x:Name="memberForm" Member="{Binding Path=SelectedMember}" />

                <StackPanel Orientation="Horizontal" Grid.Row="1" VerticalAlignment="Top" HorizontalAlignment="Right">
                    <Button x:Name="addButton" Content=" Add " Margin="4" VerticalAlignment="Top" HorizontalAlignment="Left" Command="{Binding Path=AddNewMemberCommand}" />
                    <Button x:Name="removeButton" Content=" Remove " Margin="4" VerticalAlignment="Top" HorizontalAlignment="Right" Command="{Binding Path=RemoveCommand}"/>
                    <Button x:Name="saveButton" Content=" Save All Changes " Margin="4" VerticalAlignment="Top" HorizontalAlignment="Right" Command="{Binding Path=SaveCommand}" />
                </StackPanel>

            </Grid>

        </Grid>

    </Grid>

</UserControl>
